package org.bees.cms.web.tag;

import javax.servlet.jsp.JspWriter;

import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.bees.cms.web.util.velocity.Context;

public class Paging extends Tag {
	private static final long serialVersionUID = 1327882398888836188L;

	private long current;
	private long capacity;
	private String condition;
	private long total;

	@Override
	protected void before() throws Exception {

	}

	@Override
	protected void analyze(JspWriter writer) throws Exception {
		Template template = Velocity.getTemplate("paging.vm.html");
		Context context = context();
		context.put("current", current);
		context.put("capacity", capacity);
		context.put("condition", condition);
		context.put("total", total);
		context.put("maximum", total / capacity + 1);
		template.merge(context, writer);
	}

	@Override
	protected void after() throws Exception {
		current = 0;
		capacity = 0;
		total = 0;
	}

	public long getCurrent() {
		return current;
	}

	public void setCurrent(long current) {
		this.current = current;
	}

	public long getCapacity() {
		return capacity;
	}

	public void setCapacity(long capacity) {
		this.capacity = capacity;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

}
